package com.accloud.cloudservice;

import com.accloud.common.ACConfiguration;
import com.accloud.service.ACException;
import com.accloud.service.ACMsg;
import com.accloud.service.ACObject;
import com.accloud.service.ACRankingCount;
import com.accloud.service.ACRankingMgr;
import com.accloud.service.ACRankingValue;
import java.util.ArrayList;
import java.util.List;

public class ACRankingManager extends ACBaseManager implements ACRankingMgr {
    public ACRankingManager() {
        super(ACConfiguration.RANKING_SERVICE_NAME, 1, false);
    }

    @Override // com.accloud.service.ACRankingMgr
    public void set(String name, long timestamp, double value, VoidCallback callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("userInsert");
        req.put("name", name);
        req.put("value", Double.valueOf(value));
        req.put("timestamp", Long.valueOf(timestamp));
        sendReq(req, callback);
    }

    @Override // com.accloud.service.ACRankingMgr
    public void inc(String name, long timestamp, double value, VoidCallback callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("userInc");
        req.put("name", name);
        req.put("value", Double.valueOf(value));
        req.put("timestamp", Long.valueOf(timestamp));
        sendReq(req, callback);
    }

    @Override // com.accloud.service.ACRankingMgr
    public void get(String name, String interval, long timestamp, String order, final PayloadCallback<ACRankingValue> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("userGet");
        req.put("name", name);
        req.put("timestamp", Long.valueOf(timestamp));
        req.put("interval", interval);
        req.put("order", order);
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACRankingManager.AnonymousClass1 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                callback.success(new ACRankingValue((long) resp.getInt("uid"), resp.getDouble("value"), resp.getLong("place"), resp.getLong("timestamp"), resp.getACObject("profile")));
            }
        });
    }

    @Override // com.accloud.service.ACRankingMgr
    public void ranks(String name, String interval, long timestamp, long count, String order, final PayloadCallback<List<ACRankingValue>> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("userRanks");
        req.put("name", name);
        req.put("timestamp", Long.valueOf(timestamp));
        req.put("interval", interval);
        req.put("order", order);
        req.put("count", Long.valueOf(count));
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACRankingManager.AnonymousClass2 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                ACObject profile = resp.getACObject("profile");
                List<ACObject> objects = (List) resp.get("objects");
                ArrayList arrayList = new ArrayList();
                if (objects != null) {
                    for (ACObject object : objects) {
                        arrayList.add(new ACRankingValue((long) object.getInt("uid"), object.getDouble("value"), object.getLong("place"), object.getLong("timestamp"), profile));
                    }
                }
                callback.success(arrayList);
            }
        });
    }

    @Override // com.accloud.service.ACRankingMgr
    public void totalCount(String name, String interval, long timestamp, final PayloadCallback<ACRankingCount> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("totalCount");
        req.put("timestamp", Long.valueOf(timestamp));
        req.put("name", name);
        req.put("interval", interval);
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACRankingManager.AnonymousClass3 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                callback.success(new ACRankingCount((long) resp.getInt("timestamp"), (long) resp.getInt("count")));
            }
        });
    }

    @Override // com.accloud.service.ACRankingMgr
    public void rangeCount(String name, String interval, long timestamp, double start, double end, final PayloadCallback<ACRankingCount> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("rangeCount");
        req.put("name", name);
        req.put("timestamp", Long.valueOf(timestamp));
        req.put("interval", interval);
        req.put("start", Double.valueOf(start));
        req.put("end", Double.valueOf(end));
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACRankingManager.AnonymousClass4 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                callback.success(new ACRankingCount((long) resp.getInt("timestamp"), (long) resp.getInt("count")));
            }
        });
    }

    @Override // com.accloud.service.ACRankingMgr
    public void scan(String name, String interval, long timestamp, long start, long end, String order, final PayloadCallback<List<ACRankingValue>> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("userScan");
        req.put("name", name);
        req.put("timestamp", Long.valueOf(timestamp));
        req.put("interval", interval);
        req.put("order", order);
        req.put("start", Long.valueOf(start));
        req.put("end", Long.valueOf(end));
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACRankingManager.AnonymousClass5 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                List<ACObject> objects = (List) resp.get("objects");
                ArrayList arrayList = new ArrayList();
                if (objects != null) {
                    for (ACObject object : objects) {
                        arrayList.add(new ACRankingValue((long) object.getInt("uid"), object.getDouble("value"), object.getLong("place"), object.getLong("timestamp"), object.getACObject("profile")));
                    }
                }
                callback.success(arrayList);
            }
        });
    }
}
